import time
users = {  # 用字典来存用户信息
    '小红': {'name': '小红', 'password': '234567'},
    '小白': {'name': '小白', 'password': '123789'},
    '小黑': {'name': '小黑', 'password': '258356'}
}
print("欢迎使用本软件！")
for i in range(3):
    user_name = input("请输入用户名：")
    pwd = input("请输入密码：")
    if user_name in users and users[user_name]['name'] == user_name and users[user_name]['password'] == pwd:
        print("成功登陆！")
        # 打印登陆进度条
        incomplete_sign = 50
        print("=" * 25 + '开始登陆' + "=" * 25)
        for i in range(incomplete_sign + 1):
            completed = "*" * i
            incomplete = "." * (incomplete_sign - i)
            percentage = (i / incomplete_sign) * 100
            percentage = round(percentage, 2)
            # print("\r{:.0%}[{}{}]" .format(percentage, completed, incomplete), end="")
            print(f"\r{percentage}%[{completed}{incomplete}]", end='')
            time.sleep(0.1)
        print()
        print("=" * 25 + '登陆完成' + '=' * 25)
        break
    elif user_name in users and users[user_name]['name'] != user_name and users[user_name]['password'] == pwd:
        print("用户名输入错误！")
        print("您还有%d次机会！" % (2 - i))
        if 2 - i == 0:
            print("输入错误次数过多，请稍后再试！")
    elif user_name in users and users[user_name]['name'] == user_name and users[user_name]['password'] != pwd:
        print("密码输入错误！")
        print("您还有%d次机会！" % (2 - i))
        if 2 - i == 0:
            print("输入错误次数过多，请稍后再试！")
    else:
        print("用户不存在，请注册新账号！")
        user_name = input("请输入用户名：")
        pwd = input("请输入密码：")
        users[user_name] = {'name': user_name, 'password': pwd}
